package zhh.tangbao.system.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import zhh.tangbao.system.exception.ReEntryException;
import zhh.tangbao.system.exception.ServiceException;
import zhh.tangbao.system.result.Result;

/**
 * @author 粥灰灰
 * @created 2022/8/20
 * @version 1.0
 * @Description 描述
 */


@RestControllerAdvice
public class GlobalExceptionHandler {

    Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(ServiceException.class)
    public Result ServiceExceptionHandler(ServiceException e) {
        log.error(e.getMessage());
        return Result.fail().setMsg(e.getMessage());
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public Result IllegalArgumentExceptionHandler(IllegalArgumentException e) {
        log.error(e.getMessage());
        return Result.fail().setMsg(e.getMessage());
    }

    @ExceptionHandler(ReEntryException.class)
    public Result ReEntryExceptionHandler(ReEntryException e) {
        log.error(e.getMessage());
        return Result.needReEntry(e.getMessage());
    }


}
